<html>
<head><meta charset="utf-8"><title>macro expansion at type alias position · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html">macro expansion at type alias position</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="233227469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233227469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233227469">(Apr 05 2021 at 20:52)</a>:</h4>
<p>Hey, I am slowly reading/digging more into <code>hir_def</code> to figure out an approach to support macro expansion at type alias positions:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Ty</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Ty</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">U32</span><span class="o">!</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">type</span> <span class="nc">TayTo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">U32</span><span class="o">!</span><span class="p">();</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">testy</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">a</span>: <span class="o">&lt;</span><span class="p">()</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">Mom</span><span class="o">&gt;</span>::<span class="n">M</span><span class="p">;</span><span class="w"> </span><span class="c1">// currently: {unknown}</span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">b</span>: <span class="nc">TayTo</span><span class="p">;</span><span class="w"> </span><span class="c1">// currently: {unknown}</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>I think the first step might be to modify <code>TypeAlias</code>' ast (therefor <code>rust.ungrammar</code>) to also include an optional <code>MacroCall</code>. I was then looking into the <code>ItemTree</code> lowering code, which  should "lower" the <code>MacroCall</code> besides storing the type. At this point I am quite unsure, whether we would want to expand the <code>MacroCall</code> eagerly here (and the implications of doing so), but this wouldn't fit into the current "model", whereas just like current <code>MacroCalls</code>  are expanded later in <code>nameres::Collector</code>.</p>
<p>I was wondering what approach/direction would be the "best" here.</p>



<a name="233229910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233229910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233229910">(Apr 05 2021 at 21:06)</a>:</h4>
<p>They cannot be expanded by the item tree, since that's crate-independent</p>



<a name="233232012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233232012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233232012">(Apr 05 2021 at 21:15)</a>:</h4>
<p>I think <a href="https://github.com/rust-analyzer/rust-analyzer/blob/4bc8a018302d53951ae855ba57d07095a16ef182/crates/hir_def/src/type_ref.rs#L180">here</a> would be a good place to start? it seems to me the syntax tree already supports macro calls in types, we just have to lower them there</p>



<a name="233233219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233233219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233233219">(Apr 05 2021 at 21:21)</a>:</h4>
<p>Thanks, I'll dig more into it!</p>



<a name="233861457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233861457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233861457">(Apr 09 2021 at 17:31)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> Is it actually possible to expand the macrocall at that point? (since that TypeRef will be constructed at ItemTree lowering)</p>



<a name="233861724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233861724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233861724">(Apr 09 2021 at 17:33)</a>:</h4>
<p>no, it needs to be expanded later</p>



<a name="233861947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233861947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233861947">(Apr 09 2021 at 17:35)</a>:</h4>
<p>hmm true</p>



<a name="233861987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233861987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233861987">(Apr 09 2021 at 17:35)</a>:</h4>
<p>is there some part at this stage that also does this (delayed expansion)?</p>



<a name="233862463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233862463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233862463">(Apr 09 2021 at 17:39)</a>:</h4>
<p>you can either add a <code>Macro</code> variant to reflect this, or split <code>TypeRef</code> into pre- and post-expansion</p>



<a name="233862542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233862542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233862542">(Apr 09 2021 at 17:39)</a>:</h4>
<p>the expansion would happen in the <code>struct_data</code> (etc.) queries, as well as during body lowering (for types in <code>let</code> statements and expressions)</p>



<a name="233862910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233862910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233862910">(Apr 09 2021 at 17:42)</a>:</h4>
<p>I actually thought about your first suggestion,  however I wasn't quite sure how exactly that would work. But I think I might give this a go first! Thanks.</p>



<a name="233885406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233885406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233885406">(Apr 09 2021 at 20:26)</a>:</h4>
<p>I am getting the following macro expansion with:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">expander</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Expander</span>::<span class="n">new</span><span class="p">(</span><span class="n">db</span><span class="p">,</span><span class="w"> </span><span class="n">file_id</span><span class="p">,</span><span class="w"> </span><span class="n">module_id</span><span class="p">);</span><span class="w"></span>
<span class="k">match</span><span class="w"> </span><span class="fm">dbg!</span><span class="p">(</span><span class="n">expander</span><span class="p">.</span><span class="n">enter_expand</span>::<span class="o">&lt;</span><span class="n">ast</span>::<span class="n">Type</span><span class="o">&gt;</span><span class="p">(</span><span class="n">db</span><span class="p">,</span><span class="w"> </span><span class="n">call</span><span class="p">))</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// doesn't work because see below</span>
</code></pre></div>
<p>on</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="fm">macro_rules!</span><span class="w"> </span><span class="n">U32</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="kt">u32</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Ty</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Ty</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">U32</span><span class="o">!</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>:</p>
<div class="codehilite"><pre><span></span><code>[crates/hir_def/src/body.rs:136] db.parse_or_expand(file_id) = Some(
    MACRO_ITEMS@0..3
      MACRO_CALL@0..3
        PATH@0..3
          PATH_SEGMENT@0..3
            NAME_REF@0..3
              IDENT@0..3 &quot;u32&quot;
    ,
)
[crates/hir_def/src/data.rs:139] expander.enter_expand::&lt;ast::Type&gt;(db, call) = Ok(
    ExpandResult {
        value: None,
        err: None,
    },
)
</code></pre></div>
<p>I didn't expect that the expansion would have a <code>MACRO_CALL</code> or <code>MACRO_ITEMS</code>. Am I doing something wrong?</p>



<a name="233893579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233893579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233893579">(Apr 09 2021 at 21:19)</a>:</h4>
<p>Ah  <code>hir_expand::db::to_fragment_kind</code> doesn't seem to cover this.</p>



<a name="233894286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233894286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233894286">(Apr 09 2021 at 21:22)</a>:</h4>
<p>Nice, extending the match with <code>MACRO_TYPE =&gt; FragmentKind::Type,</code> fixes the macro expansion.</p>



<a name="233979071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233979071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233979071">(Apr 10 2021 at 19:07)</a>:</h4>
<p>Now that I think about this, it might be easier to start with macro expansion in pattern position – that only has to happen inside item bodies, which happens in a single place in rust-analyzer</p>



<a name="233979461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233979461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233979461">(Apr 10 2021 at 19:12)</a>:</h4>
<p>I might look into that</p>



<a name="233980956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233980956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233980956">(Apr 10 2021 at 19:34)</a>:</h4>
<p>I actually do have a working implementation at type alias position. I am currently working on cleaning up stuff. My hopes were that fixing this would get <a href="https://github.com/rust-analyzer/rust-analyzer/issues/4774">https://github.com/rust-analyzer/rust-analyzer/issues/4774</a> to work, however it seems that there is some issue with the complex trait bounds somewhere.</p>



<a name="233981228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233981228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233981228">(Apr 10 2021 at 19:38)</a>:</h4>
<p>However I might wanna open a WIP PR, I am absolutely not sure about the general ideal ive taken.</p>



<a name="233981535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233981535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233981535">(Apr 10 2021 at 19:44)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/pull/8462">https://github.com/rust-analyzer/rust-analyzer/pull/8462</a></p>



<a name="233991191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233991191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233991191">(Apr 10 2021 at 21:36)</a>:</h4>
<p>opened <a href="https://github.com/rust-analyzer/rust-analyzer/pull/8463">https://github.com/rust-analyzer/rust-analyzer/pull/8463</a> for macros in pattern position</p>



<a name="233998006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233998006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233998006">(Apr 10 2021 at 23:29)</a>:</h4>
<p>I am currently looking into "expanding" a <code>TypeRef</code>, which now has Macro variant. My first attempt would be to walk the <code>TypeRef</code> and mutably <code>mem::replace</code> all nested<code>Macro</code> variants.  I am not sure if this is a good idea since we might <code>mem::replace</code> an interned TypeRef, which I think might cause other issues because of, well interning?</p>



<a name="233998124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233998124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233998124">(Apr 10 2021 at 23:31)</a>:</h4>
<p>Interned TypeRefs are immutable, so you can only get immutable refs to the interior</p>



<a name="233998179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233998179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233998179">(Apr 10 2021 at 23:32)</a>:</h4>
<p>the expansion will have to allocate and intern a new typeref</p>



<a name="233998204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233998204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233998204">(Apr 10 2021 at 23:32)</a>:</h4>
<p>Uff, that's kind of cumbersome xD.</p>



<a name="233998343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233998343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233998343">(Apr 10 2021 at 23:34)</a>:</h4>
<p>okay it's 1am. lets go</p>



<a name="233998472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/233998472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#233998472">(Apr 10 2021 at 23:36)</a>:</h4>
<p>yeah, it's basically a type fold but without having type folding infra</p>



<a name="234056538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234056538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234056538">(Apr 11 2021 at 15:56)</a>:</h4>
<p>I am currently using the following helper:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">panic</span>::<span class="p">{</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">UnwindSafe</span><span class="p">};</span><span class="w"></span>

<span class="cp">#[inline(always)]</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">replace_with</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">UnwindSafe</span><span class="p">,</span><span class="w"> </span><span class="n">F</span>: <span class="nb">FnOnce</span><span class="p">(</span><span class="n">T</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">T</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">UnwindSafe</span><span class="o">&gt;</span><span class="p">(</span><span class="n">dest</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">f</span>: <span class="nc">F</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">dest_ptr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dest</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="n">T</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">old</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dest_ptr</span><span class="p">.</span><span class="n">read</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">new</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">panic</span>::<span class="n">catch_unwind</span><span class="p">(</span><span class="o">||</span><span class="w"> </span><span class="n">f</span><span class="p">(</span><span class="n">old</span><span class="p">))</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="nb">Ok</span><span class="p">(</span><span class="n">val</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">val</span><span class="p">,</span><span class="w"></span>
<span class="w">            </span><span class="nb">Err</span><span class="p">(</span><span class="n">err</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="fm">eprintln!</span><span class="p">(</span><span class="s">"{:?}"</span><span class="p">,</span><span class="w"> </span><span class="n">err</span><span class="p">);</span><span class="w"></span>
<span class="w">                </span><span class="n">std</span>::<span class="n">process</span>::<span class="n">abort</span><span class="p">();</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="p">};</span><span class="w"></span>
<span class="w">        </span><span class="n">dest_ptr</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="n">new</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Is that sound? (I am using that helper in my hacky type folding code). If so, would it be okay if i could add that to stdx?</p>



<a name="234056575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234056575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234056575">(Apr 11 2021 at 15:57)</a>:</h4>
<p>The catch with that helper is that an inner panic causes an abort. But I'd say that's okay?</p>



<a name="234058432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234058432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Mcnab <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234058432">(Apr 11 2021 at 16:28)</a>:</h4>
<p>It's probably better to use <a href="https://docs.rs/replace_with/0.1.7/replace_with/">https://docs.rs/replace_with/0.1.7/replace_with/</a> directly?</p>



<a name="234058652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234058652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234058652">(Apr 11 2021 at 16:32)</a>:</h4>
<p>It seems weird to me that you need this in general</p>



<a name="234061280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234061280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234061280">(Apr 11 2021 at 17:15)</a>:</h4>
<p>Well, I am currently trying to transform/map each vec entry (<code>Vec&lt;TypeRef&gt;</code>) without allocating another vec . Afaik my options are replace_with or two <code>mem::replace</code>s with a dummy (<code>TypeRef::Error</code>?).</p>



<a name="234061308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234061308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234061308">(Apr 11 2021 at 17:15)</a>:</h4>
<p>Or is this premature optimization, idk.</p>



<a name="234061406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234061406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234061406">(Apr 11 2021 at 17:17)</a>:</h4>
<p>whats preventing you from borrowing from the vec and writing to the reference directly? I'm not sure I understand why this function here would be required</p>



<a name="234061479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234061479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234061479">(Apr 11 2021 at 17:18)</a>:</h4>
<p>I would prefer replacing with <code>TypeRef::Error</code>, but I'm not sure you need to avoid the allocation? won't you need a copy in the end anyway?</p>



<a name="234061512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234061512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234061512">(Apr 11 2021 at 17:19)</a>:</h4>
<p>I was following the following pattern:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">fold_type_ref</span><span class="p">(</span><span class="n">type_ref</span>: <span class="nc">TypeRef</span><span class="p">,</span><span class="w"> </span><span class="n">f</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="k">impl</span><span class="w"> </span><span class="nb">FnMut</span><span class="p">(</span><span class="o">&amp;</span><span class="n">TypeRef</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Option</span><span class="o">&lt;</span><span class="n">TypeRef</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">TypeRef</span><span class="w"> </span><span class="p">{</span><span class="o">..</span><span class="p">.}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">fold_path</span><span class="p">(</span><span class="n">path</span>: <span class="nc">Path</span><span class="p">,</span><span class="w"> </span><span class="n">f</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="k">impl</span><span class="w"> </span><span class="nb">FnMut</span><span class="p">(</span><span class="o">&amp;</span><span class="n">TypeRef</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Option</span><span class="o">&lt;</span><span class="n">TypeRef</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Path</span><span class="w"></span>
</code></pre></div>



<a name="234061571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234061571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234061571">(Apr 11 2021 at 17:20)</a>:</h4>
<p>My attempt before was based on mutable borrows however that didn't work well for some reason.</p>



<a name="234061722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234061722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234061722">(Apr 11 2021 at 17:22)</a>:</h4>
<p>the item tree will contain unexpanded <code>TypeRef</code>s, right? so you can't expand in place anyway. I'd probably make it <code>&amp;TypeRef -&gt; TypeRef</code>?</p>



<a name="234061760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234061760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234061760">(Apr 11 2021 at 17:23)</a>:</h4>
<p>btw <span class="user-mention" data-user-id="211727">@Jonas Schievink  [he/him]</span> I just realized that <code>TypeRef</code> still uses boxes instead of <code>Interned</code>, did you try interning the insides of typerefs as well?</p>



<a name="234061821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234061821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234061821">(Apr 11 2021 at 17:24)</a>:</h4>
<p>It's kind of hard to explain. Here is my current attempt: <a href="https://gist.github.com/cynecx/3f406413e7c57e233d43a32abbbfcee8">https://gist.github.com/cynecx/3f406413e7c57e233d43a32abbbfcee8</a></p>



<a name="234061947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234061947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234061947">(Apr 11 2021 at 17:26)</a>:</h4>
<p>I think I would first try to write the expansion code specifically, without building a whole <code>fold</code> infrastructure, and make it clone as it goes</p>



<a name="234061978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234061978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234061978">(Apr 11 2021 at 17:27)</a>:</h4>
<p>I actually doubt that we will have many more uses for such an infrastructure, because mostly that happens with lowered <code>Ty</code>s</p>



<a name="234062060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062060">(Apr 11 2021 at 17:29)</a>:</h4>
<p>maybe we could even do the expansion during lowering? <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> I hesitate to make type lowering more complicated, but it might fit in there</p>



<a name="234062120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062120">(Apr 11 2021 at 17:30)</a>:</h4>
<p>(I'm talking about <a href="https://github.com/rust-analyzer/rust-analyzer/blob/7be06139b632ee615fc18af04dd67947e2c794b2/crates/hir_ty/src/lower.rs#L151">this</a>)</p>



<a name="234062135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062135">(Apr 11 2021 at 17:30)</a>:</h4>
<p>What kind of lowering are you talking about?</p>



<a name="234062149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062149">(Apr 11 2021 at 17:30)</a>:</h4>
<p>oh didnt see your recent message yet</p>



<a name="234062178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062178">(Apr 11 2021 at 17:31)</a>:</h4>
<p>that's going from <code>TypeRef</code> to <code>Ty</code>, it could probably macroexpand as it goes</p>



<a name="234062184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062184">(Apr 11 2021 at 17:31)</a>:</h4>
<p>Oh</p>



<a name="234062186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062186">(Apr 11 2021 at 17:31)</a>:</h4>
<p>I'm not sure it's a good idea though</p>



<a name="234062244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062244">(Apr 11 2021 at 17:32)</a>:</h4>
<p>Didn't <span class="user-mention" data-user-id="211727">@Jonas Schievink  [he/him]</span>  actually mentioned this on GH?:</p>
<p>He wrote: </p>
<blockquote>
<p>Yeah, I currently think the best way to do this is to add another variant to the existing TypeRef. It should then be replaced by the expanded type during lowering, or left as-is if the macro fails to resolve/expand.</p>
</blockquote>
<p>I was wondering what lowering he was talking about.</p>



<a name="234062253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062253">(Apr 11 2021 at 17:33)</a>:</h4>
<p>maybe <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="234062377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062377">(Apr 11 2021 at 17:34)</a>:</h4>
<p>That would be even easier actually, without type folding.</p>



<a name="234062740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062740">(Apr 11 2021 at 17:40)</a>:</h4>
<p>I was actually thinking about <code>TypeRef -&gt; TypeRef</code> lowering in <code>data.rs</code>, <code>adt.rs</code>, and body lowering, but doing it when lowering to <code>Ty</code> might be easier, yeah</p>



<a name="234062950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062950">(Apr 11 2021 at 17:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="129457">Florian Diebold</span> <a href="#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position/near/234061760">said</a>:</p>
<blockquote>
<p>btw <span class="user-mention silent" data-user-id="211727">Jonas Schievink  [he/him]</span> I just realized that <code>TypeRef</code> still uses boxes instead of <code>Interned</code>, did you try interning the insides of typerefs as well?</p>
</blockquote>
<p>No, but that's probably something we should do</p>



<a name="234062953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234062953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cynecx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234062953">(Apr 11 2021 at 17:44)</a>:</h4>
<blockquote>
<p>I was actually thinking about TypeRef -&gt; TypeRef lowering in <a href="http://data.rs">data.rs</a>, <a href="http://adt.rs">adt.rs</a>, and body lowering, </p>
</blockquote>
<p>That's partially how my local branch works right now. Does it have any implications when TypeRef expansion is moved to the TypeRef -&gt; Ty lowering code? Besides being easier to implement? (Also that would include inserting TypeRef expansion calls everytime a TypeRef is referenced in <a href="http://data.rs">data.rs</a>, <a href="http://adt.rs">adt.rs</a>, ...)</p>



<a name="234064454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/macro%20expansion%20at%20type%20alias%20position/near/234064454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/macro.20expansion.20at.20type.20alias.20position.html#234064454">(Apr 11 2021 at 18:06)</a>:</h4>
<p>it slightly changes what's recomputed in which cases when code changes, ... but probably not enough to matter <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>